/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: MaterialGroupController
 * Author:   Administrator
 * Date:     2021/8/4 0004 14:20
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package cn.hxlc.tie.demo.modular.material.controller;


import cn.hxlc.tie.demo.modular.material.model.param.MaterialgroupParam;
import cn.hxlc.tie.demo.modular.material.model.result.MaterialgroupResult;
import cn.hxlc.tie.demo.modular.material.service.MaterialgroupService;
import cn.hxlc.tie.libs.scanner.annotation.GetResource;
import cn.hxlc.tie.libs.scanner.annotation.PostResource;
import cn.hxlc.tie.libs.scanner.stereotype.ApiResource;
import cn.hxlc.tie.model.page.PageResult;
import cn.hxlc.tie.model.web.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static cn.hxlc.tie.model.web.response.ResponseData.DEFAULT_SUCCESS_CODE;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Administrator
 * @create 2021/8/4 0004
 * @since 1.0.0
 */
@RestController
@ApiResource(name = "物料分类管理", path = "/materialGroup")
@Api(tags = "物料分类")
public class MaterialgroupController {

    @Autowired
    private MaterialgroupService materialgroupService;

    @GetResource(name = "查询分组树", path = "/queryGroupTree", requiredPermission = false)
    @ApiOperation(value = "查询分组树")
    public ResponseData queryGroupTree() {
        return ResponseData.success(this.materialgroupService.queryTree());
    }

    @GetResource(name = "分页查询列表", path = "/queryListPage", requiredPermission = false)
    @ApiOperation(value = "分页查询列表", response = MaterialgroupResult.class)
    public ResponseData queryListPage(MaterialgroupParam param) {
        PageResult<MaterialgroupResult> pageBySpec = materialgroupService.findPageBySpec(param);
        return ResponseData.success(pageBySpec);
    }

    @PostResource(name = "添加", path = "/add")
    @ApiOperation("新增")
    public ResponseData add(@RequestBody MaterialgroupParam param) {
        materialgroupService.add(param);
        return ResponseData.success(DEFAULT_SUCCESS_CODE,"新增成功",null);
    }

    @PostResource(name = "修改", path = "/update")
    @ApiOperation("修改")
    public ResponseData update(@RequestBody MaterialgroupParam param) {
        materialgroupService.update(param);
        return ResponseData.success(DEFAULT_SUCCESS_CODE,"修改成功",null);
    }

    @GetResource(name = "删除", path = "/delete")
    @ApiOperation("删除")
    public ResponseData delete(@RequestParam Long fid) {
        materialgroupService.delete(fid);
        return ResponseData.success(DEFAULT_SUCCESS_CODE,"删除成功",null);
    }

    @GetResource(name = "查询详情", path = "/queryDetail", requiredPermission = false)
    @ApiOperation(value = "查询详情", response = MaterialgroupResult.class)
    public ResponseData queryDetail(@RequestParam Long fid) {
        return ResponseData.success( materialgroupService.detail(fid));
    }

}
